package com.starblink.brand.widget

import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.widget.dialog.BaseBottomSheetFragment
import com.starblink.basic.route.RoutePage
import com.starblink.brand.databinding.DialogBrandChangeViewBinding

/**
 * 品牌商品修改视图模式弹窗
 */
@Route(path = RoutePage.Brand.DIALOG_CHANGE_VIEW)
class BrandChangeViewDialog() : BaseBottomSheetFragment() {
    lateinit var viewBinding: DialogBrandChangeViewBinding

    companion object {
        const val RESULT_SIMPLE_VIEW = "RESULT_SIMPLE_VIEW"
        const val ARG_RESULT = "ARG_RESULT"
    }

    @Autowired(name = RoutePage.Brand.ARG_SIMPLE_VIEW)
    @JvmField
    var isSimpleView: Boolean = true

    override fun getBindingRootView(): View {
        viewBinding = DialogBrandChangeViewBinding.inflate(layoutInflater)
        return viewBinding.root
    }

    override fun initView() {
        if(isSimpleView){
            viewBinding.vCheckBoxSimpleView.isSelected = true
        }else{
            viewBinding.vCheckBoxOriginView.isSelected = true
        }

        viewBinding.layoutSimpleView.setOnClickListener {
            isSimpleView = true
            viewBinding.vCheckBoxSimpleView.isSelected = true
            viewBinding.vCheckBoxOriginView.isSelected = false
        }
        viewBinding.layoutOriginView.setOnClickListener {
            isSimpleView = false
            viewBinding.vCheckBoxSimpleView.isSelected = false
            viewBinding.vCheckBoxOriginView.isSelected = true
        }

        viewBinding.vClose.setOnClickListener {
            dismiss()
        }
        viewBinding.btnCancel.setOnClickListener {
            dismiss()
        }
        viewBinding.btnConfirm.setOnClickListener {
            setFragmentResult(
                RESULT_SIMPLE_VIEW,
                bundleOf(ARG_RESULT to isSimpleView)
            )
            dismiss()
        }
    }
}